<?PHP
 
class Admin_webpay_Controller extends controller_admin{
	function __construct(){
		parent::__construct();
	 	$this->assign('nav','在线充值事务');
		$this->assign('menuid1','5');
		$this->assign('menuid2','3'); 
		//权限判断
		factory::module('admin')->authSys('trans');
		
	}

	  
	
	function index__(){
		if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST')
		{
			#得到传递过来的参数
			$_POST=format::addslash_deep($_POST);
			if(!isset($_POST['start']))			$_POST['start']			= 0;
			if(!isset($_POST['limit']))			$_POST['limit']			= 10;
			if(!isset($_POST['sort']))				$_POST['sort']			= 'a.id';
			if(!isset($_POST['dir']))				$_POST['dir']				= 'DESC';
			if(!isset($_POST['keywords']))   $_POST['keywords']  = '';  
			if(!isset($_POST['ended']))   $_POST['ended']  = '';
			if(!isset($_POST['b_date']))   $_POST['b_date']  = '';
			if(!isset($_POST['e_date']))   $_POST['e_date']  = '';
  	  #查询条件
			$sql_where = ' where 0=0 '.func::speedsearch($_POST['keywords'],array( 'a.orderamount','a.orderid','b.username','b.name','a.created'));
			if($_POST['ended'] != ''){
				$sql_where .= ' and a.ended="'.$_POST['ended'].'" ';
			}
			if($_POST['b_date']!=''){
				$sql_where .= ' and a.created >= "'.$_POST['b_date'].' 00:00:00" ';	
			}
			if($_POST['e_date']!=''){
				$sql_where .= ' and a.created <= "'.$_POST['e_date'].' 23:59:59" ';	
			}
			#排序信息
			$sql_order = " ORDER BY ".$_POST['sort'].' '.$_POST['dir']." LIMIT ".$_POST['start'].", ".$_POST['limit'];
			#先查总数 
			$sql = "
			select 
			count(a.id) 
			from `t_webpaylog` a
			left join t_user b on a.user_id=b.id
			".$sql_where ;  
			
			$db = factory::getDBO();
			$rows = $db->LoadResult($sql); 
			if($rows){
				#检索出具体数据
				$sql = "select
					a.*,
					b.username,
					b.name as user_name
				from `t_webpaylog` a
				left join t_user b on a.user_id=b.id
				".$sql_where.$sql_order;
				$rs = $db->LoadAssocList($sql);
				#输出结果
				echo '({"total":"'.$rows.'","results":'.json_encode($rs).'})';
			}else{
				echo '({"total":"0","results":[]})';
			}
			exit();
		}
	 	$this->assign('nav','在线充值事务');
	}
	public function view__(){
	
		$_GET=format::addslash_deep($_GET);
		$id = intval($_GET['id']);
		$db = factory::getDBO();
		$rs = $db->loadassoc('select 
			a.*,
			b.username as username,
			b.name as user_name
			from `#__webpaylog` a
			left join `#__user` b on a.user_id=b.id 
			where a.id="'.$id.'"  and a.deleted=0
		');
		if($rs === false) exit('没有查到任何资料，请重新操作！'); 
		$this->assign('rs',$rs); 
	}
	public function userbalance__(){
		$_GET=format::addslash_deep($_GET);
		$id = $_GET['id'];
		$db = factory::getDBO();
		$rs = $db->loadassoc('
			select
				a.id,
				a.name,
				a.username,
				a.balance,
				a.point
			from `t_user` a
			where  a.id="'.$id.'" 
		');
		if(!$rs){
			exit('操作失败！,没有查到信息！');
		} 
	 	$this->assign('rs',$rs);
	}
	
	 
}
?>